using System;
using System.Collections.Generic;
using System.Text;
using ENTITIES;
using DAL;
using Utility;


namespace BUS
{
   public class SanPhamBUS
    {
        public static void Insert(TBSanPham sp)
        {
            SanPhamDAL spDAL = new SanPhamDAL();
            spDAL.Insert(sp);
        }
        public static void Update(TBSanPham sp)
        {
            SanPhamDAL spDAL = new SanPhamDAL();
            spDAL.Update(sp);
        }
        public static void Delete(int iD)
        {
            SanPhamDAL spDAL = new SanPhamDAL();
            spDAL.Delete(iD);
        }
        public static tbSanPhamCollection Get(string where,
            int pageindex,
            int pagesize,
            string orderby,
            string orderdirection,
            out int total)
        {
            SanPhamDAL spDAL = new SanPhamDAL();
            return spDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbSanPhamCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            SanPhamDAL spDAL = new SanPhamDAL();
            return spDAL.Get(cri.Criter, 0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static TBSanPham GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbSanPhamColumns.MaSP.ToString(), Condition.EQUAL, iD);
            SanPhamDAL spDAL = new SanPhamDAL();
            tbSanPhamCollection sanphamcollection = spDAL.Get(cri.Criter,
                  0, 0, tbSanPhamColumns.MaSP.ToString(), OrderDirection.ASC.ToString(), out total);
            if (sanphamcollection.Count > 0)
                return sanphamcollection[0];
            return null;
        }
        public static tbSanPhamCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            SanPhamDAL spDAL = new SanPhamDAL();
            return spDAL.Get(cri.Criter, 1, number,
             tbSanPhamColumns.MaSP.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbSanPhamCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            SanPhamDAL spDAL = new SanPhamDAL();
            return spDAL.Get(cri.Criter, 1, number,
               tbSanPhamColumns.MaSP.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
    }

